package top.shenluw.springdemo.mybatis;

import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Shenluw
 * 创建日期：2019/6/27 12:18
 */
public interface UserMapper {
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name")
    })
    @Select("select * from user")
    List<User> getAll();

    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name")
    })
    @Select("select * from user where id =#{id}")
    User getOne(Integer id);

    @Insert("insert into user(name) values(#{name})")
    // SelectKey 用于绑定查询插入生成的id
    @SelectKey(keyProperty = "id", before = false, statement = "call identity()", resultType = Integer.class)
    void save(User user);

    @Update("update user set name = #{name} where id = #{id}")
    int update(User user);

    @Delete("delete from user where id = #{id}")
    int delete(Integer id);

}
